﻿@{
    ViewData["Title"] = "文号列表";
    var catelist = ViewBag.catelist as IEnumerable<ArticleCate>;
}

<div class="content-top-nav">
    <h3 style="color:#444"><i class="layui-icon layui-icon-home"></i>@ViewData["Title"] </h3>
    <hr>
</div>
<div class="layui-fluid" style="margin-bottom:50px;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" action="" lay-filter="FormSearch" enctype="multipart/form-data">
                    <div class="layui-card-body ">
                        <div class="layui-form">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="title" id="title" placeholder="标题搜索" class="layui-input" style="width:220px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="docnumber" id="docnumber" placeholder="文号搜索" class="layui-input" style="width:220px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="clercator" id="clercator" placeholder="经办人" class="layui-input" style="width:100px;">
                            </div>
                            <div class="layui-inline layui-show-xs-block" style="width:120px;">
                                <select name="searchcid" id="searchcid" lay-verify="">
                                    <option value="0">所有类别</option>
                                    @foreach (var item in catelist)
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                                </select>
                            </div>
                            <div class="layui-inline layui-show-xs-block" style="width:120px;">
                                <select id="miji" name="miji" lay-verify="required">
                                    <option value="">全部密级</option>
                                    <option value="0">无</option>
                                    <option value="1">秘密</option>
                                    <option value="2">机密</option>
                                    <option value="3">绝密</option>
                                </select>
                            </div>

                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" data-type="reload" id="searchBtn"><i class="layui-icon">&#xe615;</i></button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <script type="text/html" id="toolbarAE">
                <div class="layui-btn-container">
                    @if (await Authorizer.AuthView(PermissionKeys.ArticleDocreceived_AddOrEdit))
                    {
                                <button class="layui-btn layui-btn-sm data-add-btn"><i class="layui-icon">&#xe642;</i>新增</button>
                    }
                </div>
            </script>

            <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="cateUrlTpl">
                {{d.cateName}}
            </script>
            <script type="text/html" id="contentUserTpl">
                {{d.nickname}}
            </script>
            <script type="text/html" id="docNumberTpl">
               {{d.docNumber}}
            </script>
            <script type="text/html" id="mijiTpl">
                 {{#  if(d.miji == 0){ }}
                  无
                {{#  } else if(d.miji==1) { }}
                  秘密
                {{#  } else if(d.miji==2) { }}
                  机密
                {{#  } else if(d.miji==3) { }}
                  绝密
                {{#  } }}
            </script>
            <script type="text/html" id="contentUrlTpl">
                <a lay-event="print">{{d.title}}</a>
            </script>
            <script type="text/html" id="currentTableBar">
                <div class="layui-btn-group">
                    @if (await Authorizer.AuthView(PermissionKeys.ArticleDocreceived_AddOrEdit))
                    {
                                <a class="layui-btn layui-btn-sm " lay-event="print"><i class="layui-icon">&#xe66d;</i>预览</a>
                                <a class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
                    }
                    @if (await Authorizer.AuthView(PermissionKeys.ArticleDocreceived_Delete))
                    {
                                <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>
                    }
                    else
                    {
                                    <a class="layui-btn layui-btn-sm layui-btn-disabled"><i class="layui-icon">&#xe640;</i>删除</a>
                    }
                </div>
            </script>

        </div>
    </div>
</div>
<script>
    layui.define(function () {
        var table = layui.table, $ = layui.jquery, layer = layui.layer, form = layui.form;

        form.render();

        form.val('FormSearch', {
            searchcid: @ViewBag.cid,
        });

        table.render({
            elem: '#currentTableId',
            //url: '/resapi/table.json',
            url: '/Admin/Docreceived/Index?cid=@ViewBag.cid&json=1',
            toolbar: '#toolbarAE',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            cols: [[
                { field: 'id', width: 80, title: '序号', sort: true },
                { field: 'cateName', width: 100, title: '类别', templet: '#cateUrlTpl' },
                { field: 'docNumber', width: 220, title: '来文文号', align: 'center', templet: '#docNumberTpl' },
                { field: 'miji', width: 80, title: '密级', align: 'center', templet: '#mijiTpl' },
                { field: 'title', title: '标题', templet: '#contentUrlTpl' },
                { field: 'nickname', width: 100, title: '登记人', align: 'center', templet: '#contentUserTpl' },
                { field: 'deptName', width: 100, title: '部门', align: 'center' },
                { field: 'clercator', width: 100, title: '经办人', align: 'center' },
                { field: 'greatTime', width: 120, title: '发布时间', sort: true },
                { title: '操作', width: 280, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            id: 'tableReload',
            page: true
        });

        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            loadMain('/Admin/Docreceived/AddOrEdit?cid=@ViewBag.cid');
            return false;
        });
        // 监听删除操作
        $(".data-delete-btn").on("click", function () {
            var checkStatus = table.checkStatus('currentTableId'), data = checkStatus.data;
            layer.alert(JSON.stringify(data));
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                loadMain('/Admin/Docreceived/AddOrEdit?&id=' + data.id + '&cid=' + data.cid);
                return false;
            } else if (obj.event === 'print') {
                var index = layer.open({
                    type: 2,
                    title: ['打印预览', 'font-size:18px;'],
                    area: ['1000px', '800px'],
                    shadeClose: "true",
                    content: '/Admin/Docreceived/AddOrEdit?print=1&id=' + data.id
                });
            } else if (obj.event === 'delete') {
                layer.confirm('删除确认？', function (index) {
                    $.post('/Admin/Docreceived/Delete?id=' + data.id, function (res) {
                        if (res.status == 1) {
                            layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                obj.del();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                        }
                    });
                });
            }
        });

        //搜索重载表格
        $('#searchBtn').on('click', function () {
            table.reloadData('tableReload', {
                method: 'get',
                where: {
                    Title: $('#title').val(),
                    SearchCid: $('#searchcid').val(),
                    Miji: $('#miji').val(),
                    Clercator: $('#clercator').val(),
                    DocNumber: $('#docnumber').val(),
                },
                page: {
                    curr: 1
                },
                page: true,
            });
            return false;
        });
    });
</script>